package com.habdqn.easybuy.web.front.shop;

import com.habdqn.easybuy.entity.Shop;
import com.habdqn.easybuy.entity.User;
import com.habdqn.easybuy.service.ShopService;
import com.habdqn.easybuy.service.impl.ShopServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author Xing.Jiejian
 * @date 2020/12/2
 */
@WebServlet(name = "ShopListServlet",urlPatterns = "/shop")
public class ListServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取当前登录用户
        User user = (User) request.getSession().getAttribute("currentUser");
        // 根据用户获取对应的购物车集合
        ShopService shopService = new ShopServiceImpl();
        List<Shop> shops = shopService.queryByUserId(user.getId(),true);
        request.setAttribute("shops",shops);
        request.getRequestDispatcher("/WEB-INF/front/shopping.jsp").forward(request,response);
    }
}
